use Operation;

package ToggleWall;

sub perform{
    my $self = shift;
    my ($entity, $map, $pos) = ($self->params->{ENTITY},
				$self->params->{MAP},
				$self->params->{POS});

    my ($x, $y) = @{$pos};

    my $cell = $map->tiles->[$x][$y];
    my @constructions = @{$cell->contents->category("CONSTRUCTION")};
    
    my $lm = $self->{LogManager};
    
    $lm->log(@constructions);
    $lm->log(scalar(@constructions));

    if(scalar(@constructions) == 0){
	$cell->contents->add(Wall->spawn(), "CONSTRUCTION");
    }else{
	foreach(@constructions){
	    $cell->contents->remove($_);
	}
    }

    my  $result = ActionResult->new("DONE", "OK");
    return $result;
}

1;
